<?php
/**
 * Created by PhpStorm.
 * User: 鄢鹏权
 * Date: 2017/8/22
 * Time: 15:57
 */
return [
    'SWOOLE'=>[
        'AUTO_RELOAD_TIME'=>3,
        'CONF'=>[
            'daemonize' => !APP_DEBUG, //自动进入守护进程
            'task_worker_num' => 5,//开启task功能，
            'dispatch_mode '=>3,//轮询模式
            'worker_num'=>5,
        ],
        'TABLE'=>[],
        'LISTEN'=>[
            //来自客户端前端的请求处理方式
            [
                'NAME'=>'11',
                'HOST'=>'0.0.0.0',
                'PORT'=>'17423',
                'TYPE'=>'Socket',
                'DISPATCH'=>function($data){
                    if($data){
                        $data=json_decode($data,true);
                        $_REQUEST['_msg']=$data;
                        return $data['t']&&$data['i']?[
                            'i'=>'Console/Mcu/'.$data['i'],
                            'd'=>$data['d'],
                            't'=>$data['t']
                        ]:null;
                    }
                    return null;
                },//HTTP通道上行的数据
                'OUT'=>function($data){
                    return json_encode([
                        'i'=>$_REQUEST['_msg']['i'],
                        't'=>$_REQUEST['_msg']['t'],
                        'd'=>$data,
                    ]);
                }
            ],
            [
                'NAME'=>'NodeMCU端口',
                'HOST'=>'0.0.0.0',
                'PORT'=>'17420',
                'TYPE'=>'WebSocket',
                'DISPATCH'=>function($data){
                    if($data){
                        $data=json_decode($data,true);
                        $_REQUEST['_msg']=$data;
                        //N表示Node指令，S表示系统指令，F表示文件指令，U表示用户指令
                        \Tsy\Tsy::$i = 'N'.$data['i'];
                        \Tsy\Tsy::$t = $data['t'];
                        return $data['t']&&$data['i']?[
                            'i'=>'Console/Mcu/'.$data['i'],
                            'd'=>$data['d'],
                            't'=>$data['t']
                        ]:null;
                    }
                    return null;
                },//HTTP通道上行的数据
                'OUT'=>function($data){
                    return json_encode([
                        'i'=>\Tsy\Tsy::$i,
                        't'=>\Tsy\Tsy::$t,
                        'd'=>$data,
                    ]);
                }
            ],
            [
                'NAME'=>'WebSocket',
                'HOST'=>'0.0.0.0',
                'PORT'=>'17421',
                'TYPE'=>'WebSocket',
                'DISPATCH'=>function($data){
                    broadcast(17420,$data);
                },
                'OUT'=>function(){},
                'ON'=>[
//                    'close'=>[$SocketObject,'close'],
                ]
            ],
        ],
    ],
];